package io.renren.modules.slideshow.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import io.renren.common.validator.group.AddGroup;
import io.renren.common.validator.group.UpdateGroup;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.slideshow.entity.SlideshowEntity;
import io.renren.modules.slideshow.service.SlideshowService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;




/**
 * 
 * 
 * @author ÑîË§
 * @email 
 * @date 2018-11-09 21:17:52
 */
@RestController
@RequestMapping("/slideshow/slideshow")
public class SlideshowController {
	@Autowired
	private SlideshowService slideshowService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("slideshow:slideshow:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<SlideshowEntity> slideshowList = slideshowService.queryList(query);
		int total = slideshowService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(slideshowList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{slideshowid}")
	@RequiresPermissions("slideshow:slideshow:info")
	public R info(@PathVariable("slideshowid") Integer slideshowid){
		SlideshowEntity slideshow = slideshowService.queryObject(slideshowid);
		
		return R.ok().put("slideshow", slideshow);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("slideshow:slideshow:save")
	public R save(@RequestBody SlideshowEntity slideshow){
		ValidatorUtils.validateEntity(slideshow, AddGroup.class);
		Date now = new Date();
		slideshow.setCreatedate(now);
		slideshow.setUpdatedate(now);
		slideshowService.save(slideshow);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("slideshow:slideshow:update")
	public R update(@RequestBody SlideshowEntity slideshow){
		ValidatorUtils.validateEntity(slideshow, UpdateGroup.class);
		Date now = new Date();
		slideshow.setUpdatedate(now);
		slideshowService.update(slideshow);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("slideshow:slideshow:delete")
	public R delete(@RequestBody Integer[] slideshowids){
		slideshowService.deleteBatch(slideshowids);
		
		return R.ok();
	}
	
}
